/*
 * ThreadVoltageMonitor.h
 *
 *  Created on: Jan 27, 2013
 *      Author: Drew Prevost
 */

#ifndef THREADVOLTAGEMONITOR_H_
#define THREADVOLTAGEMONITOR_H_

#include <Protothread.h>
#include "Arduino.h"
#include "ThreadMicroDelay.h"
#include "RollingAvg.h"

class ThreadVoltageMonitor: public Protothread
{
public:
  ThreadVoltageMonitor(
                        uint8_t nPin,
                        int nPinMin,
                        int nPinMax,
                        int nVoltsMin,
                        int nVoltsMax,
                        unsigned long nReadFreqMicros );
  virtual ~ThreadVoltageMonitor();

  double getVoltage();

  void setReadFreqMicros( unsigned long nReadFreqMicros );
  unsigned long getReadFreqMicros();

  bool isVoltageTooLow();

  bool isVoltageTooHigh();

  void reset();

  virtual bool run();

protected:
  ThreadMicroDelay threadMicroDelay;
  RollingAvg rollingAvg;
  int nPin;
  int nPinMin;
  int nPinMax;
  int nVoltsMin;
  int nVoltsMax;
  unsigned long nReadFreqMicros;
};

#endif /* THREADVOLTAGEMONITOR_H_ */
